<template>
  <div class="app-page">
    <table-search
      label-width="80px"
      :search-form="searchFormItem"
      :on-submit="handleQuery"
      :on-reset="handleQuery"
    />
    <el-card>
      <div class="content">
        <table-paging
          :table-list="tableList"
          :table-column="tableColumn"
          :table-btn-width="110"
          :table-paging="tablePaging"
          :table-total="tableTotal"
          @pagingChange="handlePaginChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { fetchUserFindPage, fetchUserUpdateStatus } from '@/api/basicinfo/basicdata/resident'
import { TableSearch, TablePaging } from '@/components'
import { searchFormItem, tableColumn } from './config'

export default {
  name: 'Resident',
  components: { TableSearch, TablePaging },
  data() {
    return {
      searchFormItem,
      searchFormData: {},

      tableList: [],
      tableTotal: 0,
      tablePaging: {
        page: 1,
        pagesize: 10
      },
      tableColumn: tableColumn(this.handleUpdateStatus)
    }
  },
  created() {
    this.postFindPage()
  },
  methods: {
    handleQuery(values) { // 查询点击
      this.searchFormData = values
      this.tablePaging = {
        page: 1,
        pagesize: 10
      }
      this.postFindPage()
    },

    handleUpdateStatus(id, status) {
      this.postUpdateStatus(id, status)
    },

    handlePaginChange(pageInfo) { // 分页改变
      this.tablePaging = pageInfo
      this.postFindPage()
    },

    postFindPage() { // 获取列表
      fetchUserFindPage({ ...this.searchFormData, ...this.tablePaging }).then(res => {
        const { records, current, size, total } = res
        this.tableList = records
        this.tablePaging = {
          page: current,
          pagesize: size
        }
        this.tableTotal = total
      })
    },

    postUpdateStatus(id, status) { // 更新状态
      fetchUserUpdateStatus({ id, status }).then(res => {
        this.$message.success('操作成功!')
        this.postFindPage()
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
